<script setup lang="ts">
import { inject, nextTick } from 'vue'
import { initBallsPosition } from '@renderer/views/normalScanProcess/scoutViewPage/helper'
import {
  BaseScanSeries,
  EnumScanStatus,
  NormalScanSeries,
  scanSeriesType
} from '@renderer/views/multiScanSeriesPage/types'
import { ChooseScanType, scoutParamsDefault } from '@renderer/views/multiScanSeriesPage/helper/types'
import { useScanStore } from '@renderer/store/pinia/scan'
import { useGlobalLoading } from '@renderer/utils/hooks/useGlobalLoading'

enum AddScanType {
  scout = ChooseScanType.scout,
  normalScan = ChooseScanType.normalScan,
  preMonitor = ChooseScanType.preMonitor,
  monitor = ChooseScanType.monitor
}

const {
  scanSeriesArr,
  chooseAddScanSeriesTypeDialogVisible,
  preMonitorProtocolRef,
  monitorProtocolRef,
  addScanSeriesDialogVisible,
  activeScanSeries
} = inject('multiSeries') as any

const handleClose = () => {
  chooseAddScanSeriesTypeDialogVisible.value = false
}
const scoutViewerCount = 2
const addPreOrMonitorScan = (scanType: ChooseScanType) => {
  // const { points, centerOp } = initBallsPosition()
  // let keywords = '', params = {}
  // if (scanType === ChooseScanType.preMonitor) {
  //   params = preMonitorProtocolRef.value
  //   keywords = `${params.kV.value}kV, ${params.mA.value}mA`
  // } else {
  //   params = monitorProtocolRef.value
  //   keywords = `${params.kV.value}kV, ${params.mA.value}mA`
  // }
  // let ballsInfo: any[] = []
  // if (scoutViewerCount === 1) {
  //   ballsInfo = [{
  //     points,
  //     centerOp
  //   }]
  // } else {
  //   ballsInfo = [
  //     {
  //       points,
  //       centerOp
  //     },
  //     {
  //       points,
  //       centerOp
  //     }
  //   ]
  // }
  // const series = {
  //   id: new Date().getTime(),
  //   scanSeriesName: `${scanType}`,
  //   scanType: scanType,
  //   keywords: keywords,
  //   params: params,
  //   ballsInfo: ballsInfo
  // } as scanSeriesType
  // scanSeriesArr.push(series)
  // activeScanSeries.value = {
  //   id: series.id,
  //   scanType: series.scanType
  // }
  // handleClose()
}


const addScanSeries = (scanType: AddScanType) => {
  let keywords: any = '', params: any = {}
  let series: BaseScanSeries | NormalScanSeries | null = null
  switch (scanType) {
    case AddScanType.scout:
      params = structuredClone(scoutParamsDefault)
      keywords = {
        'kV': params['kV'],
        'mA': params['mA']
      }
      series = new BaseScanSeries({
        scanSeriesName: `序列:${scanSeriesArr.length + 1}`,
        keywords: keywords,
        scanType: scanType as any,
        params: params,
        status: EnumScanStatus.c_fit,
        hasScoutImage: false,
        scoutCount: 1
      })
      break
    case AddScanType.normalScan:
      addScanSeriesDialogVisible.value = true
      break
    case AddScanType.preMonitor:
      break
    case AddScanType.monitor:
      break
    default:
      addScanSeriesDialogVisible.value = true
      break
  }
  if (series) {
    const scanStore = useScanStore()
    scanStore.scanSeriesInfo.appendScanSeries(series)
  }
  handleClose()
}

const checkHasExistScoutView = () => {
  return false
}


</script>

<template>
  <el-dialog
    title="添加扫描类型"
    width="500"
    align-center
    v-model="chooseAddScanSeriesTypeDialogVisible"
    :before-close="handleClose"
  >
    <template #default>
      <div class="w-full h-full flex justify-center items-center">
        <div class="w-[150px] flex flex-col gap-y-[10px] items-center">
          <el-button v-for="item in AddScanType"
                     class="w-full h-[50px] !m-0"
                     :key="item" @click="addScanSeries(item)">
            <span>{{ item }}</span>
          </el-button>
        </div>
      </div>
    </template>
  </el-dialog>
</template>

<style scoped>

</style>
